<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%String path = request.getContextPath() ;%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %> 
<%@ taglib uri="/WEB-INF/tld/ui.tld" prefix="ui" %> 
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
 <meta name="renderer" content="webkit">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>客户列表</title>
<jsp:include page="../../import.jsp" flush="true" />
</head>

<script type="text/javascript">
	var grid = null;
	var cstRlFlag = '${cstRlFlag}';
	$(function () {
	    initForm();
		initGrid();//注意初始化要在initForm之后,因为在初始化grid的时候需要form参数
	    searchBtnEvent();
	    clearBtnEvent();
	});
	
	//清空按钮事件
	function clearBtnEvent(){
		 $("#clearBtn").click(function(event) {
		        $("#resetBtn").click();  //重置 input-text
		        var form = liger.get("searchBar");
		        form.setData({  //重置select等特殊表单
		            "licOrgNm":" ",
		            "rgnProvCd":" ",
		            "rgnCityCd":" ",
		            "rgnCountyCd":" ",
		        });
		 });
	}
	
	//初始化表单
	function initForm(){
		$("#searchBar").ligerForm();
	}
	
	//查询按钮事件
	function searchBtnEvent(){
		 $("#searchBtn").click(function(event) {
	         var form = new liger.get("searchBar");
	         var data = form.getData();
	         for (name in data){
	            grid.setParm(name,data[name]);
	         };
	        grid.reload();
	    });
	}
	
	//查询参数
	function getSearchParams(){
		var form = new liger.get("searchBar");
        var data = form.getData();
        return data;
	}
	
	//初始化列表
	function initGrid(){
		$("#ligergrid1").ligerGrid({
	    	url: '<%=path%>/project/prjprdlicorg/initList.do',
	    	method : 'get',
	    	parms:getSearchParams(),
	        columns: [
	            { display: '省', name: 'provCdNm', minWidth: 80 , enabledSort:true},
	            { display: '市', name: 'cityCdNm', width: 60 , enabledSort:true},
	            { display: '县', name: 'distCdNm', minWidth: 80 , enabledSort:true},
	            { display: '机构名称', name: 'licOrgNm', minWidth: 150 , enabledSort:true},
	            {
	                display: '操作',
	                isSort: false,
	                width: 150,
	                render: function (rowdata, rowindex, value){
	                    var h='<a class="sq-button-hasicon" href="javascript:chooseOrgRow(';
	                        h+="'"+rowdata.id+"',";
	                        h+="'"+rowdata.licOrgNm+"'";
	                        h+=')"><i class="sqBtnIco_3"></i>选择</a>'
	                        
	                      /*   h+='<a class="sq-button-hasicon" href="javascript:removeBtn(';
	                        h+="'"+rowdata.id+"'";
	                        h+=')"><i class="sqBtnIco_7"></i>删除</a>' */
	                    return h;
	                }
	            }
	        ],
	        pageSize:10,
	        root:'rows',
	        record:'total',
	        hideLoadButton : true,
	        width: '100%',
	        height:'100%',
	        heightDiff:-2,
	        checkbox:false,
	        rownumbers:true
	    });
	    grid = liger.get("ligergrid1");
	    grid.setHeight(500);
	}
	
	//格式化时间
	function renderDate(rowdata, index, value){
		var dateStr = "";
		if(null != value){
			var date = new Date(value);
			dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DDHHMMSS);
		}
		return dateStr;
	}
	
	
	//删除所选合格证信息
	function removeBtn(id){
		/* var selectedRows = grid.getSelectedRows();
		if(selectedRows.length <1){
			$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_SELECT_MORE_ROW, SQ_type: "warring"});
			return;
		}
		var _ids = [];
		for ( var index in selectedRows) {
			_ids.push(selectedRows[index].id);
		} */
		var _ids = [];
		_ids.push(id);
		$.ligerDialog.confirm(LogUtils.LOG_CMM_DELETE_CONFIRM, function (flag) {
			if(flag == false)return;
			$.ajax({
				type: 'post',
				dataType:'json',
				data:{ids:JSON.stringify(_ids)},
				url: '<%=path%>/project/prjprdlicorg/removeByIds.do',
				success:function(msg){
					 if(msg.success == 1){
						 grid.reload();
					 }else{
						 top.$.ligerDialog.SQalert({content: msg.info,SQ_type: "error"});
					 }
				}
			});
		});
		
	}
		function addPrjPrdLicOrg(){
		        $.ligerDialog.open({title: '添加机构信息',height: 200,width: 700, url: '<%=path%>/project/prjprdlicorg/toAddPage.do',
		        	   buttons: [{
		                    text: "保存", onclick: onSave, type: 'ok', cls: 'l-dialog-btn-ok'
		                }
		            ]
		        });
		}
		 var onSave = function (item, Dialog) {
             //在子页面里绑定 frameElement.dialog.onOk = function () {}
            if (Dialog.onSave) Dialog.onSave();
        };
	
	function clearBtn(){
		var form = new liger.get("searchBar");
		form.clear();
	}
	
	function iframeResize () {
	    if (parent.mainApp) {
	        parent.mainApp.parentTab.onResize();
	    };
	}
	function chooseOrgRow(id,name){
		parent.window.document.getElementById("orgId").value=id;
		parent.window.document.getElementById("licOrgNm").value=name;
		parent.$.ligerDialog.close();
		parent.$(".l-dialog,.l-window-mask").css("display","none"); 
		// parent.grid.reload();
	}
</script>

<body class="iframeBody">
<div class="Wrapper">
<div class="searchArea">
    <form id="searchBar">
        <div class="fieldset1 clearFix">
             <div class="fieldBox col_100_auto">
				                    <div class="field">
				               <jsp:include page="../../project/prjprdlicorg/licOrgRegion.jsp" flush="true" >
								<jsp:param name="sysStdRegionDefShowLvl" value="3"/>
								<jsp:param name="sysStdRegionProvCdNm"  value="上牌地点"/>
								<jsp:param name="sysStdRegionCityCdNm" value=""/>
								<jsp:param name="sysStdRegionDistCdNm" value=""/>
							</jsp:include>
				                    </div>
				     </div> 
	      			  
	    	<div class="fieldBox">
                <div class="label">机构名称</div>
                <div class="field">
                    <input name="licOrgNm" id="licOrgNm" type="text" class="ui-textbox" value="">
                </div>
            </div>
            <div class="clearFix"></div>
            <div class="btnsBox">
               <span id="searchBtn"  class="sq-button sq-button-round"><!-- <i class="sqBtnIco_1"></i> -->查询</span>
               <span id="clearBtn" class="sq-button sq-button-round"><!-- <i class="sqBtnIco_19"></i> -->清空</span>
                <span id="addBtn" class="sq-button sq-button-round" onclick="addPrjPrdLicOrg();"><!-- <i class="sqBtnIco_4"></i> -->新增</span>
                 
            </div>
        </div>
        </form>
    </div>
<div id="ligergrid1" class="sq-grid"></div>
</div>
</body>
</html>